﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Windows.Markup;
using System.Globalization;

using KorkolaskuriBL;

namespace Korkolaskuri
{
    public partial class Window1 : Window
    {
        LoanViewModel loanViewModel = new LoanViewModel();

        public Window1()
        {
            InitializeComponent();

            this.Language = XmlLanguage.GetLanguage(CultureInfo.CurrentCulture.IetfLanguageTag);

            this.DataContext = loanViewModel;
        }

        private void paymentsDataGrid_MouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
            var loanPayment = (LoanPayment)paymentsDataGrid.SelectedItem;
            if (loanPayment != null) {
                loanViewModel.InitialBalance = loanPayment.Balance;
                loanViewModel.PaymentPeriods -= loanPayment.Period;
            }
        }

        private void fixedDurationButton_Click(object sender, RoutedEventArgs e)
        {
            loanViewModel.CalculatePeriodicPayment();
            loanViewModel.CalculatePayments();
        }

        private void fixedPaymentButton_Click(object sender, RoutedEventArgs e)
        {
            loanViewModel.CalculatePaymentPeriods();
            loanViewModel.CalculatePayments();
        }

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            loanViewModel.AddPaymentStrategy(new EqualPrincipalPortion());
            loanViewModel.AddPaymentStrategy(new EqualTotalPayment());

            loanViewModel.PaymentStrategy = loanViewModel.PaymentStrategies.First();
            loanViewModel.InitialBalance = 10000;
            loanViewModel.InterestRate = 0.12;
            loanViewModel.InterestPeriods = 12;
            loanViewModel.PaymentPeriods = 8;
            
            loanViewModel.CalculatePeriodicPayment();
            loanViewModel.CalculatePayments();
        }
    }
}
